#include "ForestState.h"
#include "../../dataengine/VorestHtmlReader.h"
#include <exception>
using namespace slotsdata;

ForestState::ForestState(std::string fileName)
{
	class ForestLoadException: public std::exception
	{
		public:
			ForestLoadException(std::string file) : m_message(std::string("Could not load forest info from file:")+file) {}
			~ForestLoadException()throw(){}
		protected:
			virtual const char* what() const throw(){ return m_message.c_str(); }
			std::string m_message;
	};

	dataengine::VorestHtmlReader reader(fileName);
	if(!reader.canLoadFile())
		throw ForestLoadException(fileName);
	m_trees = reader.readFile();
	m_numTrees = m_trees.size();
}

void ForestState::replaceTreeInfo(int ID, dataengine::VorestTreeInfo info)
{
	int numTrees = m_trees.size();
	for(int i=0;i<numTrees;++i)
		if(m_trees[i].treeID() == ID)
		{
			m_trees.at(i) = info;
			return;
		}
}

